package com.micro.center.controller;

import com.micro.center.dto.RoleDto;
import com.micro.center.service.SysRoleService;
import com.micro.common.aop.PermissionRole;
import com.micro.common.constant.Constant;
import com.micro.common.constant.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author pan.shun
 * @since 2022/7/5 16:53
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 用户授权
     */
    @PermissionRole(role = Constant.ROLE.ADMIN)
    @PostMapping("/addRole")
    public R addRole(@RequestBody RoleDto roleDto) {
        return sysRoleService.addRole(roleDto);
    }

    /**
     * 用户解权
     */
    @PermissionRole(role = Constant.ROLE.ADMIN)
    @PostMapping("/removeRole")
    public R removeRole(@RequestBody RoleDto roleDto) {
        return sysRoleService.removeRole(roleDto);
    }

    /**
     * 通过用户ID获取角色
     */
    @GetMapping("/getRoleByUserId/{userId}")
    public R getRoleByUserName(@PathVariable String userId) {
        return sysRoleService.getRoleByUserName(userId);
    }
}
